package com.lin.cli.command;


import cn.hutool.core.bean.BeanUtil;
import com.lin.generator.MainGenerator;
import com.lin.model.DataModel;
import lombok.Data;
import picocli.CommandLine.Option;
import picocli.CommandLine;
import java.util.concurrent.Callable;

@CommandLine.Command(name = "generate", description = "生成代码", mixinStandardHelpOptions = true)
@Data
public class GenerateCommand implements Callable {



        @Option(names = {"-need", "--needGit"}, arity = "0..1", description = "是否生成.gitignore", interactive = true, echo = true)
        private boolean needGit = true;
        @Option(names = {"-l", "--loop"}, arity = "0..1", description = "是否生成循环", interactive = true, echo = true)
        private boolean loop = false;
        /**
        * 核心模板生成
        */
        static DataModel.MainTemplate mainTemplate = new DataModel.MainTemplate();
        @CommandLine.Command(name = "mainTemplate", description = "核心模板生成",mixinStandardHelpOptions = true)
        @Data
        public static class MainTemplateCommand implements Runnable{
            @Option(names = {"-a", "--author"}, arity = "0..1", description = "作者注释", interactive = true, echo = true)
            private String author = "lin";
            @Option(names = {"-o", "--output"}, arity = "0..1", description = "输出信息", interactive = true, echo = true)
            private String output = "sum = ";
            @Override
            public void run() {
                mainTemplate.author = author;
                mainTemplate.output = output;
            }
        }
    @Override
    public Object call() throws Exception {
            if(loop){
            System.out.println("输入核心模板配置：");
            CommandLine mainTemplatecommandLine = new CommandLine(MainTemplateCommand.class);
            mainTemplatecommandLine.execute("--author","--output");
            }
        DataModel dataModel = new DataModel();
        BeanUtil.copyProperties(this,dataModel);
        dataModel.mainTemplate = mainTemplate;
        MainGenerator.doGenerator(dataModel);
        return null;
    }
}
